let Mock = require("mockjs")
let data = Mock.mock({
    "list|4": [{
        "id|+1": 0,
        "username": "@cname()",
        "usernick": "@cword(2,6)",
        "depart": "技术部门",
        "sex": "@cword('男女')",
        "tel": "1@increment(1000000000)",
        "email": "1@increment(1000000000)@qq.com",
        "time": "@datetime(yyyy-MM-dd HH:mm:ss SS)",
        "state": "@cword(2)",
    }]
})
Mock.mock("/api/user", "get", function (config) {
    return data
})
// 编辑/修改
Mock.mock(/\/api\/user\/edit\/\d/, "put", function (config) {
    console.log(config);

    let item = JSON.parse(config.body)
    let arr = config.url.split("/")
    let id = arr[arr.length - 1]
    data.list.splice(id, 1, item)
    return item
})
// 添加
Mock.mock("/api/user", "post", function (config) {
    let obj = JSON.parse(config.body)
    data.list.push(obj)
    return data
})
// 删除
Mock.mock(/\/api\/user\/delete\/\d/, "delete", function (config) {
    console.log(config)
    let arr = config.url.split("/")
    let id = arr[arr.length - 1]
    data.list.splice(id, 1)
    return "删除成功"
})